var express = require('express');
var router = express.Router();
var mysql =require('mysql');

/* GET home page. */
router.get('/', function(req, res, next) {
    var conn=mysql.createConnection({
        host:'localhost',
        user:'root',
        password:'123456',
        database:'stumanager'
    });
    conn.connect(err=>{
        if(err) console.log('数据库连接失败！\n '+err.stack);
        else console.log('数据库连接成功！');
    });
    var strSQL='select *from student';
    conn.query(strSQL,(err,result)=>{
        if(err){
            console.log('查询出错！');
            conn.end();
            res.send('查询出错！');
        }else{
            console.log(result);
            res.send('');
        }
    });

});

module.exports = router;
